// @flow
const str :string = 'string'
const num :number = 123 // 还能存放 NaN Infinity
const bl :boolean = true // false
const nl :null = null
const ud :void = undefined
const sb :symbol = Symbol('ss')


const arr1 : Array<number> = [1,2,3]
const arr2 : number[] = [1,2,3]
const arr3 : [string,number] = ['123',123]

const obj1 : {name:string, age:number} = {name:'string',age:34}
const obj2 : {name?:string, age:number} = {age:34}
const obj3 :{[string]:string} = {} 
obj3.name = "name"
// obj3.age = 777
// function fun(callback :(string,number) => void){
//   callback('string',100)
// }
// fun(function(str,num){
// })

// function sum (a: number, b: number) {
//   return a + b
// }
// console.log(sum(100, 55))
// console.log(sum('100', '55'))

const a:'xiaoming' = 'xiaoming' // 报错，因为只能存放字符串 xiaoming

const type : 'success' | 'warning' | 'danger' = "danger"
const b:string |number = 100

type StringOrNumber = string | number
const sn:StringOrNumber = 100

const gender:?number = null // 除了 number 还支持 null、undefined 


function passMixed(value:mixed){
  if(typeof value === 'string'){
    value.substr(1)
  }
  if(typeof value === 'number'){
    value = value * value
  }
}
passMixed(123)
passMixed({name:'xiaoming'})

function passAny(value:any){
  value.substr(1)
  value = value * value
}
passAny(123)
passAny({name:'xiaoming'})


const html :HTMLElement |null =  document.getElementById('main')